﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Oplaco.Core.BusinessLogicLayer;
using System.Data;
using System.Data.SqlClient;

namespace Oplaco.Web.DTO
{
    public static class ImageManager
    {

        public static int[] FetchImageIdentifiers(HttpContext context, int advertismentId) {

            int[] ids = null;

            try
            {               
                Oplaco.Core.DAL.AdsDataComponent.PhotosDataTable tbl = PhotosDB.GetPhotosByAdId(advertismentId);
                var query = from DataRow row in tbl.Rows select (int)row["Id"];
                if (query != null && query.Count() > 0) {
                    ids = query.ToArray<int>();
                }
                
            }
            catch (SqlException DLE)
            {
                Oplaco.Exceptions.AppService.ReplaceWithBusinessLayerException(DLE);
            }
            catch (Exception exception) {
                Oplaco.Exceptions.AppService.ProcessAndNotifyBusinessLayerException(exception);            
            }

            return ids;
        }

    }
}
